package com.yogee.topseller.activity.my;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.yogee.core.base.HttpActivity;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.R;
import com.yogee.topseller.bean.GenInfoBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.ButlerServiceLayout;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.GlideUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ButlerServiceActivity extends HttpActivity {

    @BindView(R.id.butler_service_title_layout)
    TitleLayout titleLayout;
    @BindView(R.id.butler_service_photo_iv)
    ImageView photoIv;
    @BindView(R.id.butler_service_name_tv)
    TextView nameTv;
    @BindView(R.id.butler_service_sex_iv)
    ImageView butlerServiceSexIv;
    @BindView(R.id.butler_service_phone_tv)
    TextView phoneTv;
    @BindView(R.id.butler_service_line_iv)
    ImageView butlerServiceLineIv;
    @BindView(R.id.butler_service_consultation_num_tv)
    TextView consultationNumTv;
    @BindView(R.id.butler_service_service_num_tv)
    TextView serviceNumTv;
    @BindView(R.id.butler_service_layout)
    ButlerServiceLayout butlerServiceLayout;

    private GenInfoBean genInfoBean;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_butler_service;
    }

    @Override
    protected void initView() {
        titleLayout.setActivity(this);
        titleLayout.setTitle("管家服务");
//
//        butlerServiceRv.setHasFixedSize(true);
//        butlerServiceRv.setLayoutManager(new LinearLayoutManager(this));
//        adapter = new ButlerServiceRvAdapter(this);
//        butlerServiceRv.setAdapter(adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        genInfo(AppUtil.getUserId(this));
    }

    private void genInfo(String userId) {
        HttpManager.getInstance().genInfo(userId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GenInfoBean>() {
            @Override
            public void onNext(GenInfoBean o) {
                genInfoBean = o;
                setViewData(o.getGenInfo());
            }
        }, this));
    }

    private void setViewData(GenInfoBean.GenInfo genInfo) {
        GlideUtils.circleImage1(this, genInfo.getGenPhoto(), photoIv);
        nameTv.setText(genInfo.getName());
        phoneTv.setText(genInfo.getPhone());
        serviceNumTv.setText(genInfo.getFuwuCount());
        consultationNumTv.setText(genInfo.getZixunCount());
    }

    private void callPhone(String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phone);
        intent.setData(data);
        startActivity(intent);
    }

    @OnClick({R.id.butler_service_Complaint_rl, R.id.butler_service_Consultation_rl})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.butler_service_Complaint_rl://投诉
                if (!genInfoBean.getTel().equals("")){
                    callPhone(genInfoBean.getTel());
                }
                break;
            case R.id.butler_service_Consultation_rl://咨询
                if (!genInfoBean.getTel().equals("")){
                    callPhone(genInfoBean.getTel());
                }
                break;
        }
    }
}